﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.OleDb;
using DAO;
using DTO;
using BUS;

namespace QL_xxx
{
	/// <summary>
	/// Interaction logic for KetQuaThanhToan.xaml
	/// </summary>
	public partial class KetQuaThanhToan : Window
	{
        public event OnThanhToanThanhCong onThanhToanThanhCong;
        private PhongDTO phong;
        private PhieuThuePhongDTO phieuThue;
		public KetQuaThanhToan(int _maPhieuThue,int _maPhong)
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
            phieuThue = PhieuThuePhongBUS.LayDSPhieuThuePhong(_maPhieuThue)[0];

            phong = PhongBUS.LayDSPhong(_maPhong)[0];
		}

        private void btnThoat_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBoxResult.Yes == MessageBox.Show("Bạn có chắc muốn thoát?", "Thông báo.", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No))
            {
                phong.TrangThai = 0;// thanh toan xong, doi trang thai thanh trong
                if (PhongBUS.SuaPhong(phong) == PhongBUS.suaPhongOK)
                {
                    onThanhToanThanhCong();
                }
                else
                {
                    MessageBox.Show("Lỗi cập nhật thông tin phòng chưa xác định! Vui lòng liên hệ nhà cung cấp.");
                }
                e.Cancel = false;
            }
            else
                e.Cancel = true;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            phieuThue.NgayTra = DateTime.Now;
            if (PhieuThuePhongBUS.SuaPhieuThuePhong(phieuThue) == PhieuThuePhongBUS.thanhCong)
            {
                int tien = KhachSan.tinhTienThuePhong(phieuThue);
                txtSoTien.Text = tien.ToString();
            }
            else
            {  
                MessageBox.Show("Lỗi thanh toán chưa xác định! Vui lòng liên hệ nhà cung cấp");
            }

        }
	}
}